#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2007, İşbaran Akçayır
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# Please read the COPYING file.
#

import sys
from PyQt4 import QtCore, QtGui

class TrayBase(QtGui.QSystemTrayIcon):
    def __init__(self, *args):
        apply(QtGui.QSystemTrayIcon.__init__(self))

        self.settings = QtCore.QSettings()
        self.updateInt = self.settings.value("updateinterval").toBool();

        self.trayMenu = QtGui.QMenu()

        self.action_configuration = QtGui.QAction(QtGui.QIcon("images/configure.png"), u'Configuration', self)
        self.action_about = QtGui.QAction(QtGui.QIcon("images/about.png"), u'About', self)
        self.action_quit = QtGui.QAction(QtGui.QIcon("images/quit.png"), u'Quit', self)

        self.trayMenu.addAction(self.action_configuration)
        self.trayMenu.addAction(self.action_about)
        self.trayMenu.addAction(self.action_quit)

        self.connect(self.action_configuration, QtCore.SIGNAL("triggered()"), self.phConfiguration)
        self.connect(self.action_about, QtCore.SIGNAL("triggered()"), self.phAbout)
        self.connect(self.action_quit, QtCore.SIGNAL("triggered()"), self.phQuit)

        self.trayIcon = QtGui.QIcon("images/phtray.png")
        self.setContextMenu(self.trayMenu)
        self.setIcon(self.trayIcon)
        self.setToolTip(u"Pardus Haber")
        self.show()

        """
        if(self.updateCheck):
            import urllib2
            try:
                response = urllib2.urlopen(updateServer + 'latest.txt')
                latestversion = response.read()
                if(latestversion > version and self.settings.value("popupmessages").toBool()):
                    self.tray.showMessage(u"PyQtSözlük", u"There's a higher version of PyQtSözlük available", QtGui.QSystemTrayIcon.Information, 8000)
            except:
                if(self.settings.value("popupmessages").toBool()):
                    self.tray.showMessage(u"PyQtSözlük", u"An error accured while connecting to server", QtGui.QSystemTrayIcon.Information, 8000)
        """

    def phConfiguration(self):
        print "Sozluk Configuration"

    def phAbout(self):
        print "About Pardus Haber"

    def phQuit(self):
        print u"Quiting .."
        self.deleteLater()
        sys.exit()
